package code4;

import java.util.List;
import java.util.Scanner;

// 修改学生信息
public class Code6 {

    public void modify(List<Student> list){

        System.out.println("请输入要修改的学生的学号或姓名：");
        Scanner input = new Scanner(System.in);
        String str = input.next();
        if(str.charAt(0)>='0' && str.charAt(0)<='9'){
            long l = Long.parseLong(str);
            new Code6().modify2(list, l);
        }else{
            new Code6().modify1(list, str);
        }
    }

    public void modify1(List<Student> list, String s){

        Scanner input = new Scanner(System.in);
        Student s1;
        for(int i=0; i<list.size(); i++){
            s1 = list.get(i);
            if(s.equals(s1.getName())){
                System.out.println("请输入修改后的学号：");
                long n = input.nextLong();
                s1.setId(n);
                System.out.println("请输入修改后的姓名：");
                String str = input.next();
                s1.setName(str);
                System.out.println("请输入修改后的年龄：");
                int m = input.nextInt();
                s1.setAge(m);
                return;
            }
        }
        System.out.println("没有这位学生！");
    }

    public void modify2(List<Student> list, long l){

        Scanner input = new Scanner(System.in);
        Student s;
        for(int i=0; i<list.size(); i++){
            s = list.get(i);
            if(l == (s.getId())){
                System.out.println("请输入修改后的学号：");
                long n = input.nextLong();
                s.setId(n);
                System.out.println("请输入修改后的姓名：");
                String str = input.next();
                s.setName(str);
                System.out.println("请输入修改后的年龄：");
                int m = input.nextInt();
                s.setAge(m);
                return;
            }
        }
        System.out.println("没有这位学生！");
    }
}
